package cn.csdj.sism.web;

import cn.csdj.sism.pojo.ObtainEmployment;
import cn.csdj.sism.pojo.Student;
import cn.csdj.sism.service.ClassService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import cn.csdj.sism.pojo.Class;

import java.util.HashMap;
import java.util.List;
/**
 * 班级控制器
 * 夏康
 */
@CrossOrigin
@RestController
@RequestMapping("/classes")
public class ClassController {
    //注入班级业务层
    @Autowired
    private ClassService classService;
    //添加班级
    @PostMapping
    public int insert(@RequestBody Class aClass){
        //如果为空就是添加
        if (StringUtils.isEmpty(aClass.getClassId())){
            return classService.insert(aClass);
        }else {
//            如果有值就是修改
            return classService.update(aClass);
        }
    }
    //删除班级
    @DeleteMapping("/{id}")
    public int deleteById(@PathVariable Integer id){
        return classService.deleteById(id);
    }
    //修改班级
    @PutMapping
    public int update(@RequestBody Class aClass){
        return classService.update(aClass);
    }

    //根据id查询班级
    @GetMapping("/{id}")
    public Class selectById(@PathVariable Integer id){
        return classService.selectById(id);
    }
    //查询所有班级
    @GetMapping
    public List<Class> selectAll(){
        return classService.selectAll();
    }
    @GetMapping("/page/{current}/{pageSize}")
    public IPage<Class> selectPage(@PathVariable Integer current, @PathVariable Integer pageSize){
        return classService.selectPages(current,pageSize);
    }

    /**
     * 按条件查询
     * @param heban
     * @return
     */
    @PostMapping("/heban")
    public IPage<Class> selectByHeBan(@RequestBody HashMap heban){
        return classService.selectPagesByHeBan(heban);
    }
}
